
function checkComm(obj){
	
	var petId = $(obj).attr('data-user-id');
	
	console.log(petId);
	
	var data = $('form[data-user-id='+petId+']').serialize();
	
	console.log(data);
	
	sendData(data);
}


function sendData(data){
	
	$.getJSON('../CommsDeal',data,function(data,status){
		if(status){
			alert(data[0].msg);
			window.location.reload(true);
		}
	});
	
}

$(function(){
	
	var id = $('.userId').html();
	console.log('id='+id);
	
	$.getJSON('../CommsDeal',{
		flag:0,
		id:id
	},function(data,status){
		
		$('#user-comms').empty();
		
		for(var i=0;i<data.length;i++){
			
			$('#user-comms').append('<tr><td>'+data[i].AID+'</td><td>'+data[i].ANAME+'</td><td>'+data[i].ADATE+'</td><td>'+data[i].STA+'</td><td><form class="form-horizontal" data-user-id="'+data[i].AID+'" role="form"><div class="form-group"><label for="firstname" class="col-sm-2 control-label">评论</label><div class="col-sm-8">'
					+'<input type="text" class="form-control" name="id" style="display:none" value="'+data[i].AID+'"><input type="text" style="display:none" class="form-control" name="flag" value="1"><input type="text" class="form-control" name="comment"placeholder="请输入评论内容">'
					+'</div></div><div class="form-group"><label for="lastname" class="col-sm-2 control-label">评分</label><div class="col-sm-8"><input type="number" class="form-control" name="grade"placeholder="请输入分数">'
					+'</div></div><div class="form-group"><div class="col-sm-offset-2 col-sm-10"><input type="button" class="btn btn-default" onclick="checkComm(this)" data-user-id="'+data[i].AID+'" value="确定"></div></div></form></td></tr>');
			
		}
		
	});
	
})

			